package com.elai.web.controller.baseconfig;

import com.elai.common.annotation.Log;
import com.elai.common.core.controller.BaseController;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.core.page.TableDataInfo;
import com.elai.common.enums.BusinessType;
import com.elai.common.utils.poi.ExcelUtil;
import com.elai.baseconfig.domain.OperateEquityItemDO;
import com.elai.baseconfig.service.OperateEquityItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 权益项目Controller
 *
 * @author elai
 * @date 2021-04-10
 */
@RestController
@RequestMapping("/config/equityitem")
public class OperateEquityItemController extends BaseController
{
    @Autowired
    private OperateEquityItemService operateEquityItemService;

    /**
     * 查询权益项目列表
     */
    @PreAuthorize("@ss.hasPermi('config:equityitem:list')")
    @GetMapping("/list")
    public TableDataInfo list(OperateEquityItemDO operateEquityItem)
    {
        startPage();
        List<OperateEquityItemDO> list = operateEquityItemService.selectOperateEquityItemList(operateEquityItem);
        return getDataTable(list);
    }

    @GetMapping("/getItemByType")
    public TableDataInfo getItemTypelist(OperateEquityItemDO operateEquityItem)
    {
        List<OperateEquityItemDO> list = operateEquityItemService.selectOperateEquityItemList(operateEquityItem);
        return getDataTable(list);
    }

    /**
     * 导出权益项目列表
     */
    @PreAuthorize("@ss.hasPermi('config:equityitem:export')")
    @Log(title = "权益项目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OperateEquityItemDO operateEquityItem)
    {
        List<OperateEquityItemDO> list = operateEquityItemService.selectOperateEquityItemList(operateEquityItem);
        ExcelUtil<OperateEquityItemDO> util = new ExcelUtil<OperateEquityItemDO>(OperateEquityItemDO.class);
        return util.exportExcel(list, "equityitem");
    }

    /**
     * 获取权益项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('config:equityitem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(operateEquityItemService.selectOperateEquityItemById(id));
    }

    /**
     * 新增权益项目
     */
    @PreAuthorize("@ss.hasPermi('config:equityitem:add')")
    @Log(title = "权益项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperateEquityItemDO operateEquityItem)
    {
        return toAjax(operateEquityItemService.insertOperateEquityItem(operateEquityItem));
    }

    /**
     * 修改权益项目
     */
    @PreAuthorize("@ss.hasPermi('config:equityitem:edit')")
    @Log(title = "权益项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperateEquityItemDO operateEquityItem)
    {
        return toAjax(operateEquityItemService.updateOperateEquityItem(operateEquityItem));
    }

    /**
     * 删除权益项目
     */
    @PreAuthorize("@ss.hasPermi('config:equityitem:remove')")
    @Log(title = "权益项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(operateEquityItemService.deleteOperateEquityItemByIds(ids));
    }
}
